<!--
 * @Version: 1.0
 * @Date: 2021-04-25 09:46:20
 * @LastEditTime: 2021-04-26 09:59:29
 * @Description:
-->
<template>
  <div>
    <el-card class="app-container">
      <div>
        <el-form :model="formData" inline label-width="150px">
          <div class="header_title_box">
            <h2 style="margin-right:50px">
              基本信息
            </h2>
          </div>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="付款编号：">
                <span>{{ formData.payaway_order_no }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="物流公司：">
                <span>{{ formData.logistics_company }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="应付金额(USD)：">
                <span>{{ formData.payaway_amount }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="实际付款日期：">
                <span>{{ formData.pay_time ? formData.pay_time : '-' }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="实际付款金额(USD)：">
                <span>{{ formData.payaway_amount_real !== '0' ? formData.payaway_amount_real : '-' }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="审核状态：">
                <span>{{ formData.status_text }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="申请状态：">
                <span>{{ formData.payaway_status === 0 ? '待付款' : '已付款' }}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div>
          <div class="header_title_box">
            <h2 style="margin-right:50px">
              付款单明细
            </h2>
            <div v-if="isEdit">
              <el-button v-if="selectedIdsFather.length>0" type="danger" size="mini" icon="el-icon-delete" @click="delField">批量删除</el-button>
            </div>
          </div>
          <div>
            <el-table :data="transportList" tooltip-effect="dark" style="width: 100%" border fit @selection-change="handleSelectMultiFather">
              <el-table-column v-if="isEdit" align="center" type="selection" width="55" />
              <el-table-column v-if="isEdit" align="center" label="操作" width="70" fixed>
                <template slot-scope="sales">
                  <span class="disable_style" @click="deleteField(sales.row)">删除</span>
                </template>
              </el-table-column>
              <el-table-column align="center" label="运单号" prop="transport_order_no" width="170" />
              <el-table-column align="center" label="物流公司" prop="logistics_company" />
              <el-table-column align="center" label="发货单" prop="invoice_order_no" width="150" />
              <el-table-column align="center" label="订单编号" prop="order_no" width="150" />
              <el-table-column align="center" label="平台订单编号" prop="platform_order_no" width="150" />
              <el-table-column align="center" label="平台" prop="platform" width="170" />
              <el-table-column align="center" label="店铺名称" prop="shop_name" width="170" />
              <el-table-column align="center" label="物流费用" prop="basics_fee" width="100" />
              <el-table-column align="center" label="应付金额" prop="total_fee" width="100" />
              <el-table-column align="center" label="导入时间" prop="created_at" width="155" />
              <el-table-column align="center" label="申请付款状态" prop="status" width="150">
                <template slot-scope="scope">
                  {{ scope.row.status===1? '待申请': '已申请' }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="付款单号" prop="payaway_order_no" width="170" />
            </el-table>
          </div>
        </div>
        <div class="footer-center">
          <el-button v-if="isEdit" type="primary" @click="handleSubmitNew">更 新</el-button>
          <el-button @click="handleCancelPath">{{ isEdit ? '取 消' : '返 回' }}</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loadingInfo: false,
      formData: {},
      id: '',
      selectedIdsFather: [],
      transportList: [],
      title: ''
    }
  },
  computed: {
    isEdit() {
      return this.title.includes('编辑')
    }
  },
  created() {
    this.loadingInfo = true
    this.id = this.$route.params.id
    this.title = this.$route.query.title
    this.orderInfo()
  },
  methods: {
    handleSubmitNew() {
      const data = {}
      data.ids = this.transportList.map((item) => {
        return item.id
      })
      this.$http.post(`/logisticsPayawayOrder/deleteTransportOrder/${this.id}`, data).then((res) => {
        if (res.code === 10000) {
          this.$message.success('更新成功')
          this.handleCancelPath()
        }
      })
    },
    handleCancelPath() {
      // this.$router.push({ path: '/finance/logisticsPayawayOrder' })
      this.$router.go(-1)
    },
    orderInfo() {
      this.$http.get(`/logisticsPayawayOrder/${this.id}`).then((res) => {
        if (res.code === 10000) {
          const dataObj = res.data
          this.formData = dataObj
          this.transportList = dataObj.transportList
          this.loadingInfo = false
        }
      }).catch(() => {
        this.loadingInfo = false
      })
    },
    deleteField(row) {
      const vm = this
      vm
        .$confirm(`确定删除吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          vm.transportList.splice(vm.transportList.indexOf(row), 1)
        })
    },
    // 批量删除
    delField() {
      const vm = this
      const dataArr = [...this.transportList]
      vm
        .$confirm(`确定批量删除吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          dataArr.map((arr) => {
            if (vm.selectedIdsFather.includes(arr)) {
              vm.transportList.splice(vm.transportList.indexOf(arr), 1)
            }
          })
        })
    },
    // 选择台阶费设置
    handleSelectMultiFather(data) {
      const vm = this
      vm.selectedIdsFather = []
      data.forEach(item => {
        vm.selectedIdsFather.push(item)
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
